package com.example.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.example.demo.entity.Icon;
import com.example.demo.service.IIconService;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PassToken;
import com.example.demo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * iconController
 * 
 * @author ruoyi
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/system/icon")
public class IconController
{
    @Autowired
    private IIconService iconService;

    /**
     * 查询icon列表
     */
    @PassToken
//    @PreAuthorize("@ss.hasPermi('system:icon:list')")
    @GetMapping("/list")
    public ResponseResult list(Icon icon, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "12")int pageSize)
    {
//        startPage();
        PageResult pageResult = (PageResult) iconService.IconGoodsList(icon,pageNum,pageSize);
        return  ResponseResult.createBySuccess(200,pageResult,"查询成功");
    }
//    @PassToken
//    @GetMapping("/list1")
//    public ResponseResult list1(Icon icon){
//        List<Icon> list = iconService.selectIconList(icon);
//        return  ResponseResult.createBySuccess(200,list,"查询成功");
//    }


    /**
     * 导出icon列表
     */
//    @PreAuthorize("@ss.hasPermi('system:icon:export')")
//    @Log(title = "icon", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Icon icon)
//    {
//        List<Icon> list = iconService.selectIconList(icon);
//        ExcelUtil<Icon> util = new ExcelUtil<Icon>(Icon.class);
//        util.exportExcel(response, list, "icon数据");
//    }

    /**
     * 获取icon详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:icon:query')")
    @GetMapping(value = "/{icid}")
    public ResponseResult getInfo(@PathVariable("icid") Long icid)
    {
        Icon icon = iconService.selectIconByIcid(icid);
        return ResponseResult.createBySuccess(200,icon,"查询成功");
    }

    /**
     * 新增icon
     */
//    @PreAuthorize("@ss.hasPermi('system:icon:add')")
//    @Log(title = "icon", businessType = BusinessType.INSERT)
    @PassToken
    @PostMapping
    public ResponseResult add(@RequestBody Icon icon)
    {
        int a = iconService.insertIcon(icon);
        return ResponseResult.createBySuccess(200,a,"添加成功");
    }

    /**
     * 修改icon
     */
//    @PreAuthorize("@ss.hasPermi('system:icon:edit')")
//    @Log(title = "icon", businessType = BusinessType.UPDATE)
    @PassToken
    @PutMapping
    public ResponseResult edit(@RequestBody Icon icon)
    {
        int a = iconService.updateIcon(icon);
        return ResponseResult.createBySuccess(200,a,"修改成功");
    }

    /**
     * 删除icon
//     */
//    @PreAuthorize("@ss.hasPermi('system:icon:remove')")
//    @Log(title = "icon", businessType = BusinessType.DELETE)
	@DeleteMapping("/{icids}")
    public ResponseResult remove(@PathVariable Long[] icids)
    {
        int a = iconService.deleteIconByIcids(icids);
        return ResponseResult.createBySuccess(200,a,"删除成功");
    }
}
